import '../function.dart';
import 'dart:async';
class DeviceModel {
  int id;
  int group_id;
  String device_name;
  double yesterday_income = 0.0;
  double prevday_income = 0.0;
  double balance_income = 0.0;
  double total_income = 0.0;
  String account;
  String password;
  String deviceid;
  String imeiid;
  String sessionid;
  String userid;
  String capacity;
  String used;
  String addr;
  String device_id;
  String device_sn;
  String peerid;
  String system_version;
  String ip_addr;
  String mac_address;
  String lan_ip;
  String province;
  String city;
  String isp;
  String status;
  String bind_time;
  String bind_days;
  String hardware_model;
  bool is_bind;
  String iswanke;
  String ispush;
  DeviceModel fromMap(Map device) {
    this.id = device['id'];
    this.device_name =
        device['device_name'] != null ? device['device_name'] : "";
    this.account = device['account'];
    this.password = device['password'];
    this.deviceid = device['deviceid'];
    this.imeiid = device['imeiid']??"";
    this.sessionid = device['sessionid'];
    this.userid = device['userid'];
    this.capacity = device['capacity']??"";
    this.used = device['used']??"";
    this.addr = device['addr']??"";
    this.device_id = device['device_id']??"";
    this.device_sn = device['device_sn']??"";
    this.peerid = device['peerid']??"";
    this.system_version = device['system_version']??"";
    this.ip_addr = device['ip_addr']??"IP获取中";
    this.mac_address=device['mac_address']??"";
    this.lan_ip=device['lan_ip']??"";
    this.bind_days=device['bind_days']??"";
    this.province = device['province']??"地区";
    this.city = device['city']??"地区";
    this.isp = device['isp']??"运营商";
    this.status = device['status']??"";
    this.bind_time = device['bind_time']??"";
    this.hardware_model = device['hardware_model']??"";
    if(device['is_bind']==null){
      this.is_bind =true;
    }else{
      this.is_bind =device['is_bind']=="1";
    }
    this.iswanke = device['iswanke']??"";
    this.ispush = device['ispush']??"";
    this.group_id=device['group_id']??"";
    return this;
  }

  update() {
    updateDevice(
        id: this.id,
        device_name: this.device_name,
        password: this.password,
        sessionid: this.sessionid,
        userid: this.userid,
        capacity: this.capacity,
        used: this.used,
        addr: this.addr,
        device_id: this.device_id,
        device_sn: this.device_sn,
        peerid: this.peerid,
        system_version: this.system_version,
        ip_addr: this.ip_addr,
        lan_ip: this.lan_ip,
        mac_address: this.mac_address,
        province: this.province,
        city: this.city,
        isp: this.isp,
        status: this.status,
        bind_time: this.bind_time,
        bind_days: this.bind_days,
        hardware_model: this.hardware_model,
        is_bind: this.is_bind?"1":"0",
        iswanke: this.iswanke,
        group_id:this.group_id,
        ispush: this.ispush).then((res) {
      if (res) {
        print("更新成功");
      } else {
        print("更新失败");
      }
    });
  }
  Future<bool> delete() async{
    var res=await deleteDeviceById(this.id);
    return res;
  }
}